<div id="Line-formats"></div>
<div class="header">
<p>
Previous: [[cvs: Line group formats#Line group formats|Line group formats]], Up: [[cvs: diff options#diff options|diff options]] &nbsp; |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p>
</div>

----

<div id="Line-formats-1"></div>
===== Line formats =====

Line formats control how each line taken from an input file is
output as part of a line group in if-then-else format.

For example, the following command outputs text with a one-column
change indicator to the left of the text.  The first column of output
is &lsquo;<code>-</code>&rsquo; for deleted lines, &lsquo;<code>|</code>&rsquo; for added lines, and a space
for unchanged lines.  The formats contain newline characters where
newlines are desired on output.

<div class="example" style="margin-left: 3.2em">
 cvs diff \
    --old-line-format='-%l
 ' \
    --new-line-format='|%l
 ' \
    --unchanged-line-format=' %l
 ' \
    myfile
</div>

To specify a line format, use one of the following options.  You should
quote <var>format</var>, since it often contains shell metacharacters.

;&lsquo;<code>--old-line-format=<var>format</var></code>&rsquo;
: formats lines just from the first file.

;&lsquo;<code>--new-line-format=<var>format</var></code>&rsquo;
: formats lines just from the second file.

;&lsquo;<code>--unchanged-line-format=<var>format</var></code>&rsquo;
: formats lines common to both files.

;&lsquo;<code>--line-format=<var>format</var></code>&rsquo;
: formats all lines; in effect, it sets all three above options simultaneously.

In a line format, ordinary characters represent themselves;
conversion specifications start with &lsquo;<code>%</code>&rsquo; and have one of the
following forms.

;&lsquo;<code>%l</code>&rsquo;
: stands for the contents of the line, not counting its trailing newline (if any).  This format ignores whether the line is incomplete.

;&lsquo;<code>%L</code>&rsquo;
: stands for the contents of the line, including its trailing newline (if any).  If a line is incomplete, this format preserves its incompleteness.

;&lsquo;<code>%%</code>&rsquo;
: stands for &lsquo;<code>%</code>&rsquo;.

;&lsquo;<code>%c'<var>C</var>'</code>&rsquo;
: where <var>C</var> is a single character, stands for <var>C</var>. <var>C</var> may not be a backslash or an apostrophe. For example, &lsquo;<code>%c':'</code>&rsquo; stands for a colon.

;&lsquo;<code>%c'\<var>O</var>'</code>&rsquo;
: where <var>O</var> is a string of 1, 2, or 3 octal digits, stands for the character with octal code <var>O</var>. For example, &lsquo;<code>%c'\0'</code>&rsquo; stands for a null character.

;&lsquo;<code><var>F</var>n</code>&rsquo;
: where <var>F</var> is a <code>printf</code> conversion specification, stands for the line number formatted with <var>F</var>. For example, &lsquo;<code>%.5dn</code>&rsquo; prints the line number using the <code>printf</code> format <code>&quot;%.5d&quot;</code>.  See [[cvs: Line group formats#Line group formats|Line group formats]], for more about printf conversion specifications.


The default line format is &lsquo;<code>%l</code>&rsquo; followed by a newline character.

If the input contains tab characters and it is important that they line
up on output, you should ensure that &lsquo;<code>%l</code>&rsquo; or &lsquo;<code>%L</code>&rsquo; in a line
format is just after a tab stop (e.g. by preceding &lsquo;<code>%l</code>&rsquo; or
&lsquo;<code>%L</code>&rsquo; with a tab character), or you should use the &lsquo;<code>-t</code>&rsquo; or
&lsquo;<code>--expand-tabs</code>&rsquo; option.

Taken together, the line and line group formats let you specify many
different formats.  For example, the following command uses a format
similar to <code>diff</code>&rsquo;s normal format.  You can tailor this command
to get fine control over <code>diff</code>&rsquo;s output.

<div class="example" style="margin-left: 3.2em">
 cvs diff \
    --old-line-format='&lt; %l
 ' \
    --new-line-format='&gt; %l
 ' \
    --old-group-format='%df%(f=l?:,%dl)d%dE
 %&lt;' \
    --new-group-format='%dea%dF%(F=L?:,%dL)
 %&gt;' \
    --changed-group-format='%df%(f=l?:,%dl)c%dF%(F=L?:,%dL)
 %&lt;---
 %&gt;' \
    --unchanged-group-format=<nowiki>''</nowiki> \
    myfile
</div>


----

<div class="header">
<p>
Previous: [[cvs: Line group formats#Line group formats|Line group formats]], Up: [[cvs: diff options#diff options|diff options]] &nbsp; |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p>
</div>
This document was generated on <i>a sunny day</i> using [http://www.nongnu.org/texi2html/ <i>texi2html</i>].
